#include "stm32f4xx_tim.h"
#include "time_init.h"
#include "math.h"
#include "stdio.h"
#include "usart.h"




void TIM2_Int_Init(u16 arr,u16 psc)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);  ///??TIM3?? 
	
  TIM_TimeBaseInitStructure.TIM_Period = arr; 	//??????
	TIM_TimeBaseInitStructure.TIM_Prescaler=psc;  //?????
	TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //??????
	TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; 
	
	TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);//???TIM6
	
	TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //?????6????
	TIM_Cmd(TIM2,ENABLE); //?????6
	
	NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; //???6??
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3; //?????1
	NVIC_InitStructure.NVIC_IRQChannelSubPriority=3; //????3
	NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
	NVIC_Init(&NVIC_InitStructure);
}



void TIM6_Int_Init(u16 arr,u16 psc)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);  ///??TIM3?? 
	
  TIM_TimeBaseInitStructure.TIM_Period = arr; 	//??????
	TIM_TimeBaseInitStructure.TIM_Prescaler=psc;  //?????
	TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //??????
	TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; 
	
	TIM_TimeBaseInit(TIM6,&TIM_TimeBaseInitStructure);//???TIM6
	
	TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE); //?????6????
	TIM_Cmd(TIM6,ENABLE); //?????6
	
	NVIC_InitStructure.NVIC_IRQChannel=TIM6_DAC_IRQn; //???6??
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //?????1
	NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //????3
	NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
	NVIC_Init(&NVIC_InitStructure);
}


void TIM7_Int_Init(u16 arr,u16 psc)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,ENABLE);  
	
  TIM_TimeBaseInitStructure.TIM_Period = arr; 	//??????
	TIM_TimeBaseInitStructure.TIM_Prescaler=psc;  //?????
	TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //??????
	TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; 
	
	TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStructure);//???TIM3
	
	TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE); //?????3????
	TIM_Cmd(TIM7,ENABLE); //??????3
	
	NVIC_InitStructure.NVIC_IRQChannel=TIM7_IRQn; //???3??
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //?????1
	NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //????3
	NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	
}





